global_defs {
    enable_script_security
}

vrrp_script haproxy-check {
    user root
    script "/bin/bash /etc/keepalived/check_haproxy.sh"
    interval 3
    weight -2
    fall 10
    rise 2
}

vrrp_instance haproxy-vip {
    state BACKUP
    priority 101
    interface {{ ansible_default_ipv4.interface }}
    virtual_router_id 47
    advert_int 3
    unicast_src_ip {{ inventory_hostname }}
    unicast_peer {
{% for host in groups['master'] %}{% if host != inventory_hostname %}
        {{ host }}
{% endif %}{% endfor %}
    }

    virtual_ipaddress {
        {{ kubernetes.ha.vip }}/{{ kubernetes.ha.mask }}
    }

    track_script {
        haproxy-check
    }
}